package com.xiaoze.source;

import com.xiaoze.entity.SensorReading;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

import java.util.Arrays;
import java.util.List;

/**
 * 读取集合
 *
 * @author xiaoze
 * @date 2021/12/27
 */
public class SourceCollection {

    public static void main(String[] args) throws Exception {

        // 创建环境
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();

        env.setParallelism(1);

        List<SensorReading> sensorReadings = Arrays.asList(
                new SensorReading("s1", 1747718201L, 15.4),
                new SensorReading("s2", 1747718202L, 20.4),
                new SensorReading("s3", 1747718203L, 38.4)
        );

        DataStreamSource<SensorReading> dataStream = env.fromCollection(sensorReadings);

        DataStreamSource<Integer> integerDataStream = env.fromElements(1, 2, 3, 4, 5);

        dataStream.print("data");
        integerDataStream.print("int");

        env.execute("job name");

    }

}
